﻿#pragma once
#include <opencv2/opencv.hpp>
using namespace System;
using namespace cv;



namespace MyVideo {
	public ref class MyVideoCapture
	{
		// TODO: 在此处为此类添加方法。
	private:
		cv::VideoCapture* cap;
		cv::Mat* frame;

		bool _isOpened = false;
		int _actualWidth = 640;
		int _actualHeight = 480;
		int _channels = -1;

		


	public:
		int _capIndex = 0;
		int _desiredWidth = 640;
		int _desiredHeight = 480;
		int _timeout = 5000; // 超时时间（毫秒）


		property bool IsOpened { bool get() { return _isOpened; } }
		property int ImChannels { int get() { return _channels; } }	
		property int ImWidth { int get() { return _actualWidth; } }
		property int ImHeight { int get() { return _actualHeight; } }

		property System::IntPtr PtrData
		{
			System::IntPtr get()
			{
				if (frame == nullptr || frame->empty())
				{
					return System::IntPtr::Zero;
				}
				return System::IntPtr(frame->data); // 将数据指针包装为 IntPtr
			}
		}
		MyVideoCapture();
		~MyVideoCapture();

		bool Open();
		void Close();
		bool	GrabOneFrame();

	};

}
